/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.ejb.sessionbean;

import cassys.dataaccess.DAOException;
import cassys.dataaccess.DAOFactory;
import cassys.dataaccess.StudentModuleTeamDAO;
import cassys.datatransferobjects.ModuleDTO;
import cassys.datatransferobjects.StudentModuleTeamDTO;
import java.util.ArrayList;
import javax.ejb.Stateless;

/**
 *
 * @author User
 */
@Stateless(mappedName = "StudentModuleTeamBean")
public class StudentModuleTeamBean implements StudentModuleTeamBeanRemote {

    StudentModuleTeamDAO stdModTeamDAO =  stdModTeamDAO = DAOFactory.getInstance().getStudentModuleTeamDAO();

    public StudentModuleTeamBean() {
    }

//    public void ejbCreate() {
//       
//    }

    @Override
    public ArrayList<StudentModuleTeamDTO> findAllStudnetModulTeams() throws DAOException {
        ArrayList<StudentModuleTeamDTO> arrayList = null;
        StudentModuleTeamDTO[] list = null;

        list = stdModTeamDAO.findAllStudnetModulTeams();

        if (list.length > 0) {
            arrayList = new ArrayList<StudentModuleTeamDTO>(list.length);
            for (int i = 0; i < list.length; i++) {
                arrayList.add(i, list[i]);
            }
        }
        //modules = moduleDAO.findAllModules();
        return arrayList;
    }

    @Override
    public StudentModuleTeamDTO findModule(String moduleCode) throws DAOException {
        StudentModuleTeamDTO stdModuleT = null;
        stdModuleT = stdModTeamDAO.findByModule(moduleCode);
        return stdModuleT;
    }

    @Override
    public StudentModuleTeamDTO findStudnet(String studentId) throws DAOException {
        StudentModuleTeamDTO stdModuleT = null;
        stdModuleT = stdModTeamDAO.findByStudnet(studentId);
        return stdModuleT;
    }

    @Override
    public StudentModuleTeamDTO findTeam(String teamId) throws DAOException {
        StudentModuleTeamDTO stdModuleT = null;
        stdModuleT = stdModTeamDAO.findByTeam(teamId);
        return stdModuleT;
    }

    @Override
    public ArrayList<StudentModuleTeamDTO> findAllStudnetByModule(String moduleCode) throws DAOException {
        ArrayList<StudentModuleTeamDTO> arrayList = null;
        StudentModuleTeamDTO[] list = null;

        list = stdModTeamDAO.findAllStudnetByModule(moduleCode);

        if (list.length > 0) {
            arrayList = new ArrayList<StudentModuleTeamDTO>(list.length);
            for (int i = 0; i < list.length; i++) {
                arrayList.add(i, list[i]);
            }
        }
        //modules = moduleDAO.findAllModules();
        return arrayList;
    }

    @Override
    public ArrayList<StudentModuleTeamDTO> findAllStudnetByTeam(String teamId) throws DAOException {
        ArrayList<StudentModuleTeamDTO> arrayList = null;
        StudentModuleTeamDTO[] list = null;

        list = stdModTeamDAO.findAllStudnetByTeam(teamId);

        if (list.length > 0) {
            arrayList = new ArrayList<StudentModuleTeamDTO>(list.length);
            for (int i = 0; i < list.length; i++) {
                arrayList.add(i, list[i]);
            }
        }
        //modules = moduleDAO.findAllModules();
        return arrayList;
    }
    
    @Override
    public void insertStudentModuleTeam(StudentModuleTeamDTO dto) throws DAOException {
        stdModTeamDAO.insertStudentModuleTeam(dto);
    }

    @Override
    public void updateStudentModuleTeam(StudentModuleTeamDTO dto) throws DAOException {
        stdModTeamDAO.updateStudentModuleTeam(dto);
    }

    @Override
    public void deleteStudentModuleTeam(StudentModuleTeamDTO dto) throws DAOException {
        stdModTeamDAO.deleteStudentModuleTeam(dto);
    }
    
    
     public ArrayList<StudentModuleTeamDTO> findAllModuleForStudent(String studentid) throws DAOException
     {
         
         ArrayList<StudentModuleTeamDTO> modules = null;
         StudentModuleTeamDTO[] modArray = null;
     
         modArray = stdModTeamDAO.getAllModulesForStudent(studentid);
        
        if(modArray.length > 0){
            modules = new ArrayList<StudentModuleTeamDTO>(modArray.length);
            for(int i = 0; i < modArray.length; i++)
                modules.add(i, modArray[i]);
        }
      
        return modules;
         
         
     }
     
     
       public ArrayList<StudentModuleTeamDTO> findAllModuleForTeam(String teamid) throws DAOException{
     
          ArrayList<StudentModuleTeamDTO> modules = null;
         StudentModuleTeamDTO[] modArray = null;
     
         modArray = stdModTeamDAO.getAllModulesForTeam(teamid);
        
        if(modArray.length > 0){
            modules = new ArrayList<StudentModuleTeamDTO>(modArray.length);
            for(int i = 0; i < modArray.length; i++)
                modules.add(i, modArray[i]);
        }
        return modules;
     }
}
